#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author   : Moty
# @Time     : 2024/10/18 22:39
# @File     : kc16_25.py
# @Project  : CSPT
def parse_25_Charging_Process_BMS_messages(body):
    # 解析0x25 充电过程 BMS 信息
    data = {
        "交易流水号": f"{body[0:32]}({body[0:32]})",
        "桩编号": f"{body[32:46]}({body[32:46]})",
        "枪号": f"{int(body[46:48], 16)}枪({body[46:48]})",
        "BMS 最高单体动力蓄电池电压所在编号": f"{int(body[48:50], 16) / 10}({body[48:50]})",
        "BMS 最高动力蓄电池温度": f"{int(body[50:52], 16) - 50}ºC (偏移量:-50 范围:-50ºC~+200ºC)({body[50:52]})",
        "最高温度检测点编号": f"{int(body[52:54], 16)}(范围:1~128)({body[52:54]})",
        "最低动力蓄电池温度": f"{int(body[54:56], 16) - 50}ºC (偏移量:-50 范围:-50ºC~+200ºC)({body[54:56]})",
        "最低动力蓄电池温度检测点编号": f"{int(body[56:58], 16)}(范围:1~128)({body[56:58]})",
        "BMS 单体动力蓄电池电压过高/过低":  f"{status_01(bin(int(body[58:60],16))[2:].zfill(8)[0:2])}({bin(int(body[58:60],16))[2:].zfill(8)})",
        "BMS 整车动力蓄电池荷电状态SOC 过高/过低": f"{status_01(bin(int(body[58:60],16))[2:].zfill(8)[2:4])}({bin(int(body[58:60],16))[2:].zfill(8)})",
        "BMS 动力蓄电池充电过电流": f"{status_02(bin(int(body[58:60],16))[2:].zfill(8)[4:6])}({bin(int(body[58:60],16))[2:].zfill(8)})",
        "BMS 动力蓄电池温度过高": f"{status_02(bin(int(body[58:60],16))[2:].zfill(8)[6:8])}({bin(int(body[58:60],16))[2:].zfill(8)})",
        "BMS 动力蓄电池绝缘状态": f"{status_02(bin(int(body[60:62],16))[2:].zfill(8)[0:2])}({bin(int(body[60:62],16))[2:].zfill(8)})",
        "BMS 动力蓄电池组输出连接器连接状态": f"{status_02(bin(int(body[60:62],16))[2:].zfill(8)[2:4])}({bin(int(body[60:62],16))[2:].zfill(8)})",
        "充电禁止": f"{status_03(bin(int(body[60:62],16))[2:].zfill(8)[4:6])}({bin(int(body[60:62],16))[2:].zfill(8)})",
        "预留位": f"{'预留位'}({bin(int(body[60:62],16))[2:].zfill(8)})",
    }
    formatted_data = ""
    for key, value in data.items():
        formatted_data += f"{key}: {value}\n"
    return formatted_data


def status_01(result):
    return "正常" if result == "00" else "过高" if result == "01" else "过低" if result == "10" else "未知"


def status_02(result):
    return "正常" if result == "00" else "过流" if result == "01" else "不可信状态" if result == "10" else "未知"


def status_03(result):
    return "禁止" if result == "00" else "允许" if result == "01" else "未知"


__all__ = ['parse_25_Charging_Process_BMS_messages']
